﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using NetSysData;

namespace BladeTecWebApplication
{
	public partial class Default : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{

			if (!Page.IsPostBack)
			{
				try
				{
					txtEmail.Text = Request.QueryString["email"].ToString();
					txtKey.Text = Request.QueryString["key"].ToString();
				}
				catch (Exception)
				{
				}
			}

		}

		protected void btnTakeQuiz_Click(object sender, EventArgs e)
		{
			NetSysData.NetSysData data = new NetSysData.NetSysData();
			APPLICANT a;
			int applicantId = data.ValidateLogin(txtEmail.Text, txtKey.Text);
			int attemptId = -1;

			if (applicantId != -1)
			{
				a = data.GetApplicant(applicantId);

				errorPanel.Visible = false;

				attemptId = data.StartQuiz(applicantId);
				Session["AttemptID"] = attemptId;
				Session["ApplicantName"] = a.FIRST_NAME + " " + a.LAST_NAME;
				Session["QuizName"] = a.POSITION.QUIZ.QUIZ_NAME;

				Response.Redirect("Quiz.aspx");

			}
			else
			{
				errorPanel.Visible = true;
			}

		}
	}
}